package com.credithc.customers.manager.controller;

import com.credithc.baseserv.core.codes.CoreCodes;
import com.credithc.baseserv.core.message.Message;
import com.credithc.baseserv.core.message.MessageFactory;
import com.credithc.baseserv.pageHelper.PageInfo;
import com.credithc.customers.manager.ro.SmsAccountRo;
import com.credithc.customers.manager.service.SmsAccountService;
import com.credithc.customers.manager.vo.SmsAccountVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.websocket.server.PathParam;
import java.util.HashMap;
import java.util.Map;

/**
 * @Title:
 * @Author: fby
 * @Date: 2020/03/24 11:25
 * @Description: com.credithc.customers.manager.controller
 * @Version: V1.0.0
 */
@RestController
@RequestMapping("/manager/yzt/v1")
public class SmsAccountController {
    @Autowired
    MessageFactory messageFactory;
    @Autowired
    SmsAccountService smsAccountService;

    /**
     * @description: 短信账户查询
     * @Author: fby
     * @Date: 2020/03/24 09:56
     * @return: com.credithc.baseserv.core.message.Message
     */
    @GetMapping("/smsAccount")
    public Message getloginFlow(@PathParam("smsAccount") String smsAccount,@PathParam("templateType") String templateType, @PathParam("systemSign") String systemSign, @PathParam("subSystemSign") String subSystemSign, @PathParam("smsTemplateId") String smsTemplateId, @PathParam("createTimeStart") String createTimeStart, @PathParam("createTimeEnd") String createTimeEnd,  @RequestParam("pageNo") Integer pageNo, @RequestParam("pageSize") Integer pageSize) {
        SmsAccountRo ro = new SmsAccountRo();
        ro.setSmsAccount(smsAccount);
        ro.setTemplateType(templateType);
//        ro.setSystemSign(systemSign);
        ro.setSubSystemSign(systemSign);
        ro.setSmsTemplateId(smsTemplateId);
        ro.setCreateTimeStart(createTimeStart);
        ro.setCreateTimeEnd(createTimeEnd);
        ro.setPageNo(pageNo);
        ro.setPageSize(pageSize);
        PageInfo<SmsAccountVo> list = smsAccountService.getSmsAccount(ro);
        Map<String, Object> pageInfo = new HashMap<>();
        pageInfo.put("pageInfo", list);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS, pageInfo);

    }

    /**
     * 更新账户
     */
    @PostMapping("/smsAccount/{id}")
    public Message updateDictonary(@RequestBody @Valid SmsAccountRo ro, @PathVariable(name = "id") Integer id) {
        smsAccountService.updateSmsAccount(ro, id);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }

    /**
     * 删除账户
     */
    @PostMapping("/smsAccount/remove/{id}")
    @ResponseBody
    public Message deleteDictonary(@PathVariable(name = "id") Integer id) {
        smsAccountService.remove(id);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }

    /**
     * 新增
     * @param ro
     * @return
     */
    @PostMapping("/smsAccount")
    public Message addOcrBizAccounts(@RequestBody SmsAccountRo ro){
        smsAccountService.addSmsAccount(ro);
        return messageFactory.getInstance(CoreCodes.CORE_SUCCESS);
    }
}
